/**
 * 通用混合
 * */
 import { cloneDeep } from "lodash";
 export default {
     data() {
         return {
             funupdate: "",
             funcreate: "",
             edit: true, // 新增true,编辑false
             showedit: false, // 新增编辑模态框
             subloading: false,
         };
     },
     methods: {
         /* @函数功能: 取消编辑或新增 */
         canceledit(name) {
             if (name) this.$refs[name].resetFields();
             this.showedit = false;
             this.modalparamscancel();
         },

         /* @函数功能: 提交编辑或新增 */
         submitedit(name) {
             if (name) {
                 this.$refs[name].validate((valid) => {
                     if (valid) {
                         this.submitedits(name);
                     }
                 });
             } else {
                 this.submitedits(name);
             }
         },
         submitedits(name) {
             let config = this.paramssubmit();
             if (config) {
                 this.subloading = true;
                 if (!this.edit) {
                     this.funupdate(config)
                         .then(() => {
                             this.beforsubmit(name);
                             this.subloading = false;
                         })
                         .catch(() => {
                             this.subloading = false;
                         });
                 } else {
                     this.funcreate(config)
                         .then(() => {
                             this.beforsubmit(name);
                             this.subloading = false;
                         })
                         .catch(() => {
                             this.subloading = false;
                         });
                 }
             }
         },

         /* @函数功能: 提交之后数据处理 */
         beforsubmit(name) {
             if (name) this.$refs[name].resetFields();
             if (!this.edit) this.$Message.success("编辑成功");
             else this.$Message.success("新增成功");
             this.askData();
             this.$emit("askData");
             this.modalparamscancel();
             this.showedit = false;
         },
         
         /* @函数功能: 参数置为初始值 */
         modalparamscancel(){
             this.modalparams = cloneDeep(this.modalparamsinitial)
         },
     },
 };
 